/* ***************************************************************************
 **    eeprom.c
 **
 **  Project      :
 **  Target       :
 **  Description  :
 **
 **
 **  Compiler     : HI-TECH C  Version 9.80
 **  IDE          : MPLABX v1.80
 **  Created      : June 21, 2013
 **
 **  Master
 ** ***************************************************************************/

/*****************************************************************************
 **HEADER FILES
 *****************************************************************************/

//Compiler-Standard
#include <htc.h>
#include <stdint.h>        /* For uint8_t definition */
#include <stdbool.h>       /* For true/false definition */

//Project
#include "global.h"
#include "eeprom.h"
#include "swI2C.h"

/*****************************************************************************
 **VARIABLES
 *****************************************************************************/

/*****************************************************************************
 **FUNCTIONS
 *****************************************************************************/

uint8_t EEInit(void){

    if (AckPolling(EEPROM_ID)) { //check if rtc acks on i2c bus
        return(EEPROM_NOT_RESPONDING);
    }

    return (EEPROM_INITIALIZED);
}

uint8_t EEReadByte(uint8_t address){

    uint8_t byte;

    StartI2C(); // Issue start signal
    TransmitI2C(EEPROM_ID); // Device
    TransmitI2C(address); //  Address
    StartI2C(); // Issue repeated start signal
    TransmitI2C(0xA1); // Device plus R/W=1
    byte = RecieveI2C(0);
    StopI2C(); // Issue stop signal

    return byte;
    
}

void EEWriteByte(uint8_t address, uint8_t byte){

    StartI2C(); // Issue start signal
    TransmitI2C(EEPROM_ID); // Device
    TransmitI2C(address); // Address
    TransmitI2C(byte);
    StopI2C();

}
//TODO: USER CODE


